// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

import '@/common/styles/reset.css'

import { Field, Cell, CellGroup, Area, Popup, Button, Dialog, Toast, NavBar,Swipe, SwipeItem , Row, Col,PullRefresh,Icon  } from 'vant';
import commonMethods from './assets/js/common.js'
import myConsole from './assets/js/myConsole.js'

import store from './assets/js/store'

Vue.use(Field);
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(Area);
Vue.use(Popup);
Vue.use(Button);
Vue.use(Dialog);
Vue.use(Toast);
Vue.use(NavBar);
Vue.use(PullRefresh);
Vue.use(Icon);
Vue.use(Row).use(Col);

Vue.mixin(commonMethods);
Vue.prototype.console=myConsole;
Vue.use(Swipe).use(SwipeItem);

Vue.config.productionTip = false

router.beforeEach((to, from, next) => {
  var obj =router.app;
  var r = router;
  var path = to.matched?to.matched[0].path:'';
  r.options.routes.forEach(k=>{
    if(k.path == path){
      store.commit('setTitle', {
        name: k.title
      })
    }
  });
  if(obj.$options.methods.checkBrow()){
    next();
  }else{
    if(obj.$options.methods.checkEnv()){
      next();
    }else if(path =='/query'){
      next();
    }else{
      Toast('请用支付宝扫码客户端');
    }
  }
});
router.afterEach(()=>{
  let obj = router.app;
  window.document.title =obj.$options.store.state.title;
});

/* eslint-disable no-new */
var app = new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
  store
})

